<template>
    <a-card title="广告配置">
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
          <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="广告banner图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="advertiseImage">
                  <j-image-upload  v-model="model.advertiseImage" ></j-image-upload>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="跳转类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="advertiseType">
                  <j-dict-select-tag type="list" v-model="model.advertiseType" dictCode="advertise_jump_type" placeholder="请选择跳转类型" />
                </a-form-model-item>
              </a-col>
              <!-- <a-col :span="24">
                <a-form-model-item label="关联的ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessId">
                  <a-input v-model="model.businessId" placeholder="请输入关联的ID"  ></a-input>
                </a-form-model-item>
              </a-col> -->
              <a-col :span="24" v-if="model.advertiseType == '1'">
                <a-form-model-item label="图文详情内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessContent">
                  <j-editor v-model="model.businessContent" />
                </a-form-model-item>
              </a-col>
              <a-col :span="17" :push="4">
                <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-button type="primary" @click="handleOk">提交</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </j-form-container>
      </a-spin>
    </a-card>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  export default {
    name: 'YlAdvertiseConfigModal',
    components: {},
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           advertiseImage: [
              { required: true, message: '请输入广告banner图!'},
           ],
           advertiseType: [
              { required: true, message: '请输入跳转类型!'},
           ],
        },
        url: {
          add: "/config/ylAdvertiseConfig/add",
          edit: "/config/ylAdvertiseConfig/edit",
          queryById: "/config/ylAdvertiseConfig/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      this.getConfig();
    },
    methods: {
      getConfig(){
        getAction(this.url.queryById, {id:''}).then((res)=>{
          if (res.success) {
            this.model = res.result;
          }
        })
      },
      handleOk () {
        this.submitForm();
      },
      submitForm () {
          const that = this;
          // 触发表单验证
          this.$refs.form.validate(valid => {
            if (valid) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
              }else{
                httpurl+=this.url.edit;
                 method = 'put';
              }
              httpAction(httpurl,this.model,method).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.submitCallback();
                }else{
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              })
            }

          })
      },
    }
  }
</script>
